<!--  Ofri Keidar 302933981 group 05 -->

<%@page import="controller.CmnTransactionsCtrl"%>
<%@page import="controller.EmployeeController"%>
<%@page import="model.database.DBException"%>
<%@page import="controller.CommonValues"%>
<%@page import="view.WebCommons"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="customerData" class="view.useBeans.CustomerData"
	scope="page" />
<jsp:setProperty name="customerData" property="*" />

<html>
<head>
<link rel="stylesheet" href="../../style/myTemplate/style.css"
	type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Update customer details</title>
</head>
<body>

	<span class="customHeader2">Update customer details</span>

	<div id="page">
		<div class="post">

			<div id="sidebar">
				<ul>
					<li>
						<h2>Please enter customer's number</h2>
					</li>
				</ul>
			</div>
			<div id="content">
				<!-- 			get customer's number -->
				<form METHOD=POST ACTION="UpdateCustomerDetails.jsp">
					<table>
						<tr>
							<td><INPUT TYPE=TEXT NAME=number
								SIZE=<%=WebCommons.NUMBER_SIZE%>></td>
							<td><INPUT TYPE=SUBMIT VALUE="Go!" class="mySubmitButton"></td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>

	<%
		// return to main menu
		String menuPage = (String) session.getAttribute(WebCommons.MAIN_MANU);
	%>
	<div id="footer">
		<span class="myLink"><A HREF="<%="../../menus/" + menuPage%>">Back
				to Menu</A></span>
	</div>
	
	<%
		// check submitted data	
		if (customerData.isCustomerIndicated()) {

			// verify custumer number's format
			if (customerData.getCustomerNumberValue() == null) { // no numeric value for customer number

				// display error message and ask again for details
				%>
				<span class="notify"><br>Please enter a numeric value for customer client</span>
				<%
				
			} else {

				// get numeric value for customer number
				int customerNumber = customerData.getCustomerNumberValue();

				// extract from session the suitable controller				
				EmployeeController controller = (EmployeeController) session.getAttribute(WebCommons.CONTROLLER);

				// get customer's current details
				Map<String, String> customerDetails = controller.getCustomerDetails(customerNumber);

				// check if customer exists
				if (customerDetails.isEmpty()) {

					// display error message and ask again for details
					%>
					<span class="notify"><br>Sorry, cannot update details- no customer with the number "<%=customerNumber%>"</span>
					<%
				} else { // customer exists, update details

					// store given customer number in session
					session.setAttribute(WebCommons.CUSTOMER_NUMBER, customerNumber);

					// move to page for updating customer details
					response.sendRedirect("../customerTransactions/UpdateCustomerDetails.jsp");
				}
			}
		}
	%>

</body>
</html>